package com.ruoyi.chiwen.controller;

import com.ruoyi.chiwen.controller.bo.AcrMoneyBo;
import com.ruoyi.chiwen.controller.bo.ActorBo;
import com.ruoyi.chiwen.domain.TbActor;
import com.ruoyi.chiwen.domain.TbActormoney;
import com.ruoyi.chiwen.service.ITbActorService;
import com.ruoyi.chiwen.service.ITbActormoneyService;
import com.ruoyi.chiwen.upload.BeanUtil;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class ZonghengBiz {

    @Autowired
    private ITbActorService actorService;

    @Autowired
    private ITbActormoneyService actormoneyService;


    public AjaxResult getOrderData(ActorBo actorBo) {

        if(StringUtils.isEmpty(actorBo.actorName)) return AjaxResult.error("请传入正确的主播名称");
        if(StringUtils.isEmpty(actorBo.appName)) return  AjaxResult.error("请传入正确的软件名称");
        if(StringUtils.isEmpty(actorBo.channel)) return  AjaxResult.error("请传入正确的平台名称");
        if(actorBo.cashList.size()==0) return  AjaxResult.error("请传入主播收益信息，至少一条");
        if(StringUtils.isEmpty(actorBo.appName)) return  AjaxResult.error("请传入正确的主播名称");
        TbActormoney b= new TbActormoney();
        TbActor a = BeanUtil.copyProperties(actorBo,TbActor.class);
        int c =0;
       if( actorService.insertTbActor(a)==0) return AjaxResult.error("添加失败，重试");
       List<AcrMoneyBo> bs = actorBo.getCashList();

        for (AcrMoneyBo bo:bs ) {
             b= BeanUtil.copyProperties(bo,TbActormoney.class);
             b.setActId(a.getId());
             c+=actormoneyService.insertTbActormoney(b);
        }

        return AjaxResult.success("新增"+c+"条主播："+actorBo.actorName+" 的提现记录！");
    }
}
